import Utils from "../utils/Utils";

const { prefixName, assign, defaultTo } = Utils

class UCircle implements UComponent {

    options: Required<UComponent.CircleOpt> = {
        x: 0,
        y: 0,
        zIndex: 1,
        name: prefixName('u_circle'),
        radius: 50,
        backgroundColor: 'transparent'
    }

    get name(): string {
        return this.options.name
    }

    get zIndex(): number {
        return this.options.zIndex
    }

    visible: boolean = true

    constructor(uCircleOption?: UComponent.CircleOpt) {
        this.setOption(uCircleOption)
    }

    /**
    * 设置图形参数
    * @param uCircleOption
    */
    setOption(uCircleOption?: UComponent.CircleOpt) {
        this.options = assign(this.options, defaultTo(uCircleOption, {})) as Required<UComponent.CircleOpt>
    }

    draw(ctx: CanvasRenderingContext2D) {
        const { x, y, radius, backgroundColor } = this.options
        ctx.save()
        ctx.arc(x + radius, y, radius, 0, 2 * Math.PI)
        ctx.fillStyle = backgroundColor
        ctx.fill()
    }

}

export default UCircle